package com.farm.wcp.util;

import java.io.File;
import com.farm.authority.FarmAuthorityService;
import com.farm.core.auth.domain.LoginUser;
import com.farm.parameter.FarmParameterService;
import com.farm.parameter.service.ParameterServiceInter;
import com.farm.util.spring.BeanFactory;

public class InitFilePathUtil {

	public static void iniPaths() {
		ParameterServiceInter parameterServiceImpl = (ParameterServiceInter) BeanFactory
				.getBean("parameterServiceImpl");
		LoginUser user = FarmAuthorityService.getInstance().getUserByLoginName("sysadmin");
		// 文件导出目录初始化
		if (FarmParameterService.getInstance().getParameter("config.doc.dir").equals("INIT")) {
			System.out.println("初始化目录：config.doc.dir: MAIN:" + getSysFilePath("file"));
			parameterServiceImpl.setValue("config.doc.dir", "MAIN:" + getSysFilePath("file"), user);
		}
		if (FarmParameterService.getInstance().getParameter("config.doc.file.export").equals("INIT")) {
			System.out.println("初始化目录：config.doc.file.export：" + getSysFilePath("export"));
			parameterServiceImpl.setValue("config.doc.file.export", getSysFilePath("export"), user);
		}
		parameterServiceImpl.refreshCache();
	}

	/**
	 * 生成一个默认目录
	 * 
	 * @param dirname
	 * @return
	 */
	private static String getSysFilePath(String dirname) {
		String tomcatPath = System.getProperty("catalina.home");
		return tomcatPath + File.separator + "resource" + File.separator + dirname;
	}

}
